<?php
/*
 * 进云智能生成平台
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
 */
//获取访问入口
$in=dirname(__FILE__);
$in=str_replace(dirname($in),'',$in);
$in=substr($in,1);
if(defined('BY_JYA')){
	$_SESSION['this']=$in;
}else{
	define('IN',$in);
	require '../core/core.php';
	//判断域名是否合法
	if(USER_DOMAIN){
		//开启系统分配独立域名后，不允许非系统分配的独立域名访问客户端页面
		$uniacid=str_replace(DOMAIN_PRE,'',$_SERVER['HTTP_HOST']);
		$uniacid=intval($uniacid);
		if($uniacid){
			//成功获得站点ID，存入$_RQ中备用
			$_RQ['i']=$uniacid;
		}else{
			exit('域名错误(检查是否开启了‘分配独立域名’，但是又不支持泛解析！)');
		}
	}
}
if($_SESSION['this']=='manage'){
	$_SESSION['this']=$in;
}
//判断站点是否关闭
if ($_AR['system']['close']){
	session_destroy();
	echo '站点已关闭，关闭原因：' . $_AR['system']['reason'];
	exit;
}
//获取站点信息
$uniacid=intval($_RQ['i']);
$_SESSION['fromh5wxapp']=intval($_RQ['fromh5wxapp'])?:$_SESSION['fromh5wxapp'];
$_SESSION['fromh5ttapp']=intval($_RQ['fromh5ttapp'])?:$_SESSION['fromh5ttapp'];
$_SESSION['wxapp_id']=intval($_RQ['wxapp_id'])?:$_SESSION['wxapp_id'];
if($_RQ['fromh5wxapp']){
	$_SESSION['os']='mobile';
}
if(!$uniacid && !$_SESSION['uniacid']){
	$uniacid=1;
}
$_AR['page']=core_setting('site');
if(($uniacid && $_SESSION['uniacid']!=$uniacid) || !$_SESSION['account']){
	if($uniacid && $_SESSION['uniacid']!=$uniacid){
		$_SESSION['uid']=0;
		$_SESSION['openid']='';
		$_SESSION['uniacid']=$uniacid;
		$_SESSION['isauth_base']=0;
		$_SESSION['isauth_info']=0;
		$_SESSION['fromh5wxapp']=0;
	}
	$_SESSION['account']=pdo_get('core_accounts',array('uniacid'=>$_SESSION['uniacid']),array('js_support','js_supportimg','endtime','title','logo','desc','ewm','wxapp_ewm','xiu_ewm','lxr','phone','qq','mail','cname','icp','code','address','naddress','isdiy','syscolor'));
	$kefuset=uni_setting('kefuset');
	if($kefuset){
		$_SESSION['account']=array_merge($_SESSION['account'],$kefuset);
	}
	unset($_SESSION['account']['qrticket']);
	$_SESSION['account']['js_support']=$_SESSION['account']['js_support']?:$_AR['page']['js_support'];
	$_SESSION['account']['js_supportimg']=$_SESSION['account']['js_supportimg']?:$_AR['page']['js_supportimg'];
	$_SESSION['account']['js_supportimg']=tomedia($_SESSION['account']['js_supportimg']);
	$_SESSION['account']['logo']=$_SESSION['account']['logo']?:$_AR['page']['logo'];
	$_SESSION['account']['logo']=$_SESSION['account']['logo']?tomedia($_SESSION['account']['logo']):tomedia('../core/resource/images/web-logo.jpg');
	$_SESSION['account']['llogo']=$_SESSION['account']['llogo']?:$_AR['page']['llogo'];
	$_SESSION['account']['llogo']=tomedia($_SESSION['account']['llogo']);
	$_SESSION['account']['ewm']=tomedia($_SESSION['account']['ewm']);
	$_SESSION['account']['openbackpage']=$_AR['page']['openbackpage'];
}else{
	$_SESSION['account']['syscolor']=pdo_getcolumn('core_accounts',array('uniacid'=>$_SESSION['uniacid']),'syscolor');
}
unset($uniacid);
if(!$_SESSION['uniacid'] || empty($_SESSION['account'])){
	exit('找不到指定站点!');
}
//生成token
if(!$_SESSION['token']){
	$_SESSION['token']=random(30);
}
if($_SESSION['container']!='wechat' && $_SESSION['container']!='windows' && $_SESSION['container']!='mobile'){
	//所有小程序第一次访问
	access_log();
}
//如果素材要求整理绝对路径
if(intval($_RQ['is_tomedia'])){
	$_SESSION['is_tomedia']=1;
}
$os=in_array($_SESSION['container'],array('baiduapp','aliapp','ttapp','wxapp','wechat','wxwork'))?$_SESSION['container']:'common';
require $os.'.php';
if($_SESSION['container']=='alipay'){
	require 'aliapp.php';
}
//获取到openid后，再获取粉丝信息；如果已经获取了，就不再获取
if(($os=='wechat' || $os=='wxwork') && $_SESSION['openid'] && $_SESSION['fast_getinfo']!=1){
	require $os.'.php';
}	
//定义是否来自场景体
if($_RQ['current_plugin'] && !preg_match('/\W/',$_RQ['current_plugin'])){
	$_SESSION['current_plugin']=trim($_RQ['current_plugin']);
}
if($_RQ['fromuser']){
	$_SESSION['fromuser']=intval($_RQ['fromuser']);
	//来自分享的，如果是场景体首页，刷新菜单
	if($_SESSION['current_plugin'] && $_RQ['plugin']!='core'){
		$is_legao=pdo_getcolumn('core_plugins',array('name'=>$_RQ['plugin']),'is_legao');
		if($is_legao && $_RQ['action']=='index' && (!$_RQ['current_plugin'] || preg_match('/\W/',$_RQ['current_plugin']))){
			$_SESSION['current_plugin']=$_RQ['plugin'];
		}
	}
}
if(!$_SESSION['current_plugin'] && $_RQ['plugin']!='core'){
	$is_legao=pdo_getcolumn('core_plugins',array('name'=>$_RQ['plugin']),'is_legao');
	if($is_legao){
		$_SESSION['current_plugin']=$_RQ['plugin'];
	}
}
//第三方插件入口
if($_RQ['action']=='module'){
	require ROOT_D.'/api/open_jyapi/index.php';
	exit;
}
$_AR['page']=core_setting('site');
if(!$_RQ['action']){
	if($_AR['system']['istakeover'] && $_AR['system']['takeoverplugin']){
		$_RQ['plugin'] = $_AR['system']['takeoverplugin'];
		$_RQ['action'] = 'index';
	}else{
		$id=uni_setting('default_mobile_web');
		if($_SESSION['account']['isdiy'] && $id){
			$_RQ['action']='welcome';
		}else{
			$_RQ['action']='home.welcome';
		}
		
	}
}
if(!$_RQ['plugin']){
	$_RQ['plugin']='core';
}
if($_RQ['plugin']=='jy_h5game' && $_RQ['action']=='welcome'){
	access(array('plugin'=>$_RQ['plugin'],'action'=>$_RQ['action']));
	exit;
}
if(get_access_setting($_RQ['plugin'],$_RQ['action'])){
  //普通访问，此处整理生成页面
	access(array('plugin'=>$_RQ['plugin'],'action'=>$_RQ['action']));
	exit;
}
//访问页面参数
if($_GET['plugin']){
	unset($_GET['plugin']);
}
if($_GET['i']){
	unset($_GET['i']);
}
if($_GET['action']){
	unset($_GET['action']);
}
$query='';
if($_GET){
	$query=http_build_query($_GET);
}
$access=array('plugin'=>$_RQ['plugin'],'action'=>$_RQ['action'],'query'=>$query);
$res=cfc('template')->get_customtpl($access);
$html=cfc('tools')->replace($res['search'],$res['html']);
echo $html;
//access_log();
exit;

?>